﻿using DAL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ViewModels;

namespace BLL
{
    /// <summary>
    /// 图书管理业务逻辑类
    /// </summary>
    public class BookBLL
    {
        private BookDAL dal;//定义图书数据访问类对象：dal
        private DataSet ds;

        public BookBLL()
        {
            dal = new BookDAL();//实例化dal对象
            ds = new DataSet();
        }
        /// <summary>
        /// 获取所有书籍信息列表
        /// </summary>
        /// <returns>DataSet</returns>
        public DataSet GetBookList()
        {
            ds = dal.GetBookList();
            if (ds != null)
                return ds;
            else
                return null;
        }
        /// <summary>
        /// 根据索书号返回关联书籍信息列表
        /// </summary>
        /// <param name="inputstring">索书号字符串</param>
        /// <returns>DataSet</returns>
        public DataSet GetBookListByID(string inputstring)
        {
            ds = dal.GetBookListByID(inputstring);
            if (ds != null)
                return ds;
            else
                return null;
        }
        public DataSet GetBookListByName(string inputstring)
        {
            ds = dal.GetBookListByName(inputstring);
            if (ds != null)
                return ds;
            else
                return null;
        }
        public DataSet GetBookListByAuthor(string inputstring)
        {
            ds = dal.GetBookListByAuthor(inputstring);
            if (ds != null)
                return ds;
            else
                return null;
        }

        public DataSet GetBookClasses()
        {
            ds = dal.GetBookClasses();
            if (ds != null)
                return ds;
            else
                return null;
        }
        public string GetBookClassName(string classid)
        {
            return dal.GetBookClassName(classid);
        }

        /// <summary>
        /// 数据查重
        /// </summary>
        /// <param name="vm">书籍视图模型vm</param>
        /// <returns>bool，true：重复；false：非重复</returns>
        public bool ChecingDuplication(BookVM vm)
        {
            return dal.ChecingDuplication(vm);
        }
        public object EditBook(BookVM vm,string operation)
        {
            if (ChecingDuplication(vm) && operation=="I")
                return "该书已在库有记录，请勿重复插入！";
            else
            {
                return dal.EditBook(vm, operation);
            }
        }
    }
}
